home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / Copland ResourcesLib / System8Resources.cp < prev    next >
Text File  |  1995-08-24  |  7KB  |  398 lines

  1. /*
  2.     File:        System8Resources.cp
  3.  
  4.     Contains:    The System 7 resource manager redefined in
  5.                     terms of the System 8 Resource Manager.
  6.                 Make this file as a shared library.
  7.                 
  8.     Written by: Chris Thomas <ckt@best.com>
  9.                     bug reports, suggestions, comments welcome!
  10.                     
  11.     Version:    1.0
  12.     
  13.     Copyright:    © 1995 Chris K. Thomas.  All Rights Reserved.
  14.                 © 1995 Apple Computer, Inc.  All Rights Reserved.
  15.  
  16.     Change History (most recent first):
  17.      
  18.                8/23/95    ckt        Created.
  19.                
  20.     I decided that I didn't want to litter my resource
  21.     code with dozens of #ifdefs for System 7-8 compatibility,
  22.     and this was so easy!
  23.     
  24.     One thing I find odd about the Copland Res Manager
  25.     is that it supports UInt32 numbers of resources by
  26.     index, but still only SInt16 by id.
  27.     
  28.     These could probably be inlined for C++.
  29.     
  30.     While this appears to work for me, it may not work for you.
  31.     No warranties express or implied, no guaranteed results.
  32. */
  33.  
  34. #include "System8Resources.h"
  35.  
  36. OSStatus RMCloseResFile(ResFileRefNum refNum)
  37. {
  38.     OSStatus        outErr = 0L;
  39.     
  40.     CloseResFile(refNum);
  41.     
  42.     outErr = ResError();
  43.     return outErr;
  44. }
  45.  
  46. OSStatus RMUseResFile(ResFileRefNum refNum)
  47. {
  48.     OSStatus        outErr = 0L;
  49.     
  50.     UseResFile(refNum);
  51.     
  52.     outErr = ResError();
  53.     return outErr;
  54. }
  55.  
  56. OSStatus RMCurResFile(ResFileRefNum* refNum)
  57. {
  58.     OSStatus        outErr = 0L;
  59.     
  60.     *refNum = CurResFile();
  61.     
  62.     outErr = ResError();
  63.     return outErr;
  64. }
  65.  
  66. OSStatus RMHomeResFile(Handle theResource, ResFileRefNum *refNum)
  67. {
  68.     OSStatus        outErr = 0L;
  69.     
  70.     *refNum = HomeResFile(theResource);
  71.     
  72.     outErr = ResError();
  73.     return outErr;
  74. }
  75.  
  76. OSStatus RMAddResource(Handle theData, ResType theType, ResID theID, ConstStr255Param name)
  77. {
  78.     OSStatus        outErr = 0L;
  79.     
  80.     AddResource(theData, theType, theID, name);
  81.     
  82.     outErr = ResError();
  83.     return outErr;
  84. }
  85.  
  86. OSStatus RMRemoveResource(Handle theResource)
  87. {
  88.     OSStatus        outErr = 0L;
  89.     
  90.     RemoveResource(theResource);
  91.     
  92.     outErr = ResError();
  93.     return outErr;
  94. }
  95.  
  96. OSStatus RMCountTypes(Boolean oneDeep, UInt32 *count)
  97. {
  98.     OSStatus        outErr = 0L;
  99.     
  100.     if(oneDeep)
  101.         *count = Count1Types();
  102.     else
  103.         *count = CountTypes();
  104.     
  105.     outErr = ResError();
  106.     return outErr;
  107. }
  108.  
  109. OSStatus RMGetIndexedType(UInt32 index, Boolean oneDeep, ResType *theType)
  110. {
  111.     OSStatus        outErr = 0L;
  112.     
  113.     if(oneDeep)
  114.         Get1IndType(theType, index);
  115.     else
  116.         GetIndType(theType, index);
  117.     
  118.     outErr = ResError();
  119.     return outErr;
  120. }
  121.  
  122. OSStatus RMCountResources(ResType theType, Boolean oneDeep, UInt32 *count)
  123. {
  124.     OSStatus outErr = 0L;
  125.     
  126.     if(oneDeep)
  127.         *count = Count1Resources(theType);
  128.     else
  129.         *count = CountResources(theType);
  130.         
  131.     outErr = ResError();
  132.     return outErr;
  133. }
  134.  
  135. OSStatus RMGetIndexedResource(ResType theType, UInt32 index, Boolean oneDeep, Boolean resLoad, Handle *handle)
  136. {
  137.     OSStatus    outErr = 0L;
  138.     UInt8        saveResLoad;
  139.     
  140.     saveResLoad = LMGetResLoad();
  141.     SetResLoad(resLoad);
  142.     
  143.     if(oneDeep)
  144.         *handle = Get1IndResource(theType, index);
  145.     else
  146.         *handle = GetIndResource(theType, index);
  147.     
  148.     outErr = ResError();
  149.     
  150.     SetResLoad(saveResLoad);
  151.     return outErr;
  152. }
  153.  
  154.  
  155. OSStatus RMGetResource(ResType theType, ResID theID, Boolean oneDeep, Boolean resLoad, Handle *handle)
  156. {
  157.     OSStatus    outErr = 0L;
  158.     UInt8        saveResLoad;
  159.     
  160.     saveResLoad = LMGetResLoad();
  161.     SetResLoad(resLoad);
  162.     
  163.     if(oneDeep)
  164.         *handle = Get1Resource(theType, theID);
  165.     else
  166.         *handle = GetResource(theType, theID);
  167.     
  168.     outErr = ResError();
  169.     
  170.     SetResLoad(saveResLoad);
  171.     return outErr;
  172. }
  173.  
  174.  
  175. OSStatus RMGetNamedResource(ResType theType, ConstStr255Param name, Boolean oneDeep, Boolean resLoad, Handle *handle)
  176. {
  177.     OSStatus    outErr = 0L;
  178.     UInt8        saveResLoad;
  179.     
  180.     saveResLoad = LMGetResLoad();
  181.     SetResLoad(resLoad);
  182.     
  183.     if(oneDeep)
  184.         *handle = Get1NamedResource(theType, name);
  185.     else
  186.         *handle = GetNamedResource(theType, name);
  187.     
  188.     outErr = ResError();
  189.     
  190.     SetResLoad(saveResLoad);
  191.     return outErr;
  192. }
  193.  
  194.  
  195.  
  196. OSStatus RMLoadResource(Handle theResource)
  197. {
  198.     OSStatus    outErr = 0L;
  199.     
  200.     LoadResource(theResource);
  201.     
  202.     outErr = ResError();
  203.     return outErr;
  204. }
  205.  
  206.  
  207. OSStatus RMReleaseResource(Handle theResource)
  208. {
  209.     OSStatus    outErr = 0L;
  210.     
  211.     ReleaseResource(theResource);
  212.     
  213.     outErr = ResError();
  214.     return outErr;
  215. }
  216.  
  217.  
  218. OSStatus RMDetachResource(Handle theResource)
  219. {
  220.     OSStatus    outErr = 0L;
  221.     
  222.     DetachResource(theResource);
  223.     
  224.     outErr = ResError();
  225.     return outErr;
  226. }
  227.  
  228.  
  229.  
  230. OSStatus RMChangedResource(Handle theResource)
  231. {
  232.     OSStatus    outErr = 0L;
  233.     
  234.     ChangedResource(theResource);
  235.     
  236.     outErr = ResError();
  237.     return outErr;
  238. }
  239.  
  240.  
  241. OSStatus RMWriteResource(Handle theResource)
  242. {
  243.     OSStatus    outErr = 0L;
  244.     
  245.     WriteResource(theResource);
  246.     
  247.     outErr = ResError();
  248.     return outErr;
  249. }
  250.  
  251.  
  252. OSStatus RMSetResourceSize(Handle theResource, SInt32 newSize)
  253. {
  254.     OSStatus    outErr = 0L;
  255.     
  256.     SetResourceSize(theResource, newSize);
  257.     
  258.     outErr = ResError();
  259.     return outErr;
  260. }
  261.  
  262.  
  263. OSStatus RMUniqueID(ResType theType, Boolean oneDeep, ResID *idPtr)
  264. {
  265.     OSStatus    outErr = 0L;
  266.     
  267.     if(oneDeep)
  268.         *idPtr = Unique1ID(theType);
  269.     else
  270.         *idPtr = UniqueID(theType);
  271.     
  272.     outErr = ResError();
  273.     return outErr;
  274. }
  275.  
  276.  
  277.  
  278. OSStatus RMGetResAttributes(Handle theResource, ResAttributes *attributes)
  279. {
  280.     OSStatus    outErr = 0L;
  281.     
  282.     *attributes = GetResAttrs(theResource);
  283.     
  284.     outErr = ResError();
  285.     return outErr;
  286. }
  287.  
  288.  
  289. OSStatus RMGetResInfo(Handle theResource, ResType *typePtr, ResID *idPtr, Str255 name)
  290. {
  291.     OSStatus    outErr = 0L;
  292.     
  293.     GetResInfo(theResource, idPtr, typePtr, name);
  294.     
  295.     outErr = ResError();
  296.     return outErr;
  297. }
  298.  
  299.  
  300. OSStatus RMSetResInfo(Handle theResource, ResType, ResID theID, ConstStr255Param name)
  301. {
  302.     OSStatus    outErr = 0L;
  303.     
  304.     SetResInfo(theResource, theID, name);
  305.     
  306.     outErr = ResError();
  307.     return outErr;
  308. }
  309.  
  310.  
  311.  
  312. OSStatus RMSetResAttributes(Handle theResource, ResAttributes attrs)
  313. {
  314.     OSStatus    outErr = 0L;
  315.     
  316.     SetResAttrs(theResource, attrs);
  317.     
  318.     outErr = ResError();
  319.     return outErr;
  320. }
  321.  
  322.  
  323. OSStatus RMReadPartialResource(Handle theResource, UInt32 offset, void *buffer, UInt32 count)
  324. {
  325.     OSStatus    outErr = 0L;
  326.     
  327.     ReadPartialResource(theResource, (long)offset, buffer, (long)count);
  328.     
  329.     outErr = ResError();
  330.     return outErr;
  331. }
  332.  
  333.  
  334. OSStatus RMWritePartialResource(Handle theResource, UInt32 offset, const void *buffer, UInt32 count)
  335. {
  336.     OSStatus    outErr = 0L;
  337.     
  338.     WritePartialResource(theResource, (long) offset, buffer, (long) count);
  339.     
  340.     outErr = ResError();
  341.     return outErr;
  342. }
  343.  
  344. /*
  345.  * GetResourceSize returns either the size of the handle if the handle
  346.  * is not empty or the size of the resource as stored on disk (i.e.
  347.  * it has the exact semantics of GetResourceSizeOnDisk but does not
  348.  * have the confusing name).
  349.  */
  350.  
  351. OSStatus RMGetResourceSize(Handle theResource, SInt32 *size)
  352. {
  353.     OSStatus    outErr = 0L;
  354.     
  355.     *size = GetResourceSizeOnDisk(theResource);
  356.     
  357.     outErr = ResError();
  358.     return outErr;
  359. }
  360.  
  361. OSStatus RMSetResErrProc(ResErrUPP proc)
  362. {
  363.     OSStatus    outErr = 0L;
  364.     
  365.     LMSetResErrProc(proc);
  366.     
  367.     return outErr;
  368. }
  369.  
  370.  
  371. OSStatus RMSetResFileReadOnlyState(ResFileRefNum refNum, Boolean isReadOnly)
  372. {
  373.     OSStatus    outErr = 0L;
  374.     
  375.     // * should we do a GetResFileAttrs first, or does it matter?
  376.     SetResFileAttrs(refNum, isReadOnly ? mapReadOnly : 0);
  377.     
  378.     outErr = ResError();
  379.     return outErr;
  380. }
  381.  
  382.  
  383. OSStatus RMGetResFileReadOnlyState(ResFileRefNum refNum, Boolean *isReadOnly)
  384. {
  385.     OSStatus    outErr = 0L;
  386.     short        attrs;
  387.     
  388.     attrs = GetResFileAttrs(refNum);
  389.     
  390.     if(attrs & mapReadOnly)
  391.         *isReadOnly = true;
  392.     else
  393.         *isReadOnly = false;
  394.     
  395.     outErr = ResError();
  396.     return outErr;
  397. }
  398.